#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define rep(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii<=Ii##_;Ii++)
#define per(Ii,Jj,Kk) for(int Ii=(Jj),Ii##_=(Kk);Ii>=Ii##_;Ii--)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double db;
#define fir first
#define sec second
#define siz(Aa) ((int)(Aa).size())
#define all(Aa) (Aa).begin(),(Aa).end()
#define ckmx(Aa,Bb) (Aa=max(Aa,Bb))
#define ckmn(Aa,Bb) (Aa=min(Aa,Bb))
#define Fi(s) freopen(s,"r",stdin)
#define Fo(s) freopen(s,"w",stdout)
#define Fre(s) Fi(s".in"),Fo(s".out")
const int N=20;
int n,a[N],w[N],b[N];
bool check(){
	rep(i,1,n) rep(j,i+3,n){
		bool up=false,dw=false;
		rep(k,i+1,j-1){
			if(b[k]>max(b[i],b[j])) up=true;
			if(b[k]<min(b[i],b[j])) dw=true;
		}
		if(up&&dw) return false;
	}
	return true;
}
signed main(){ios::sync_with_stdio(false),cin.tie(nullptr);
	Fre("build");
	cin>>n;
	rep(i,1,n) cin>>a[i];
	iota(w+1,w+1+n,1);
	int ans=n;
	do{
		rep(i,1,n) b[i]=a[w[i]];
		if(check()){
			int res=0;
			rep(i,1,n) if(w[i]!=i) res++;
			ckmn(ans,res);
		}
	}while(next_permutation(w+1,w+1+n));
	cout<<ans<<"\n";
return 0;}
/*
*/